﻿//枚举
//----------------------------------------------------------------------------------------------------------------------------
var MapType = {
    GOOGLE: 'GOOGLE',
    BAIDU: 'BAIDU',
    SOUGOU: 'SOUGOU'
};

var ControlType =
{
    LARGE: 'LARGE',
    SCALE: 'SCALE',
    OVERVIEW: 'OVERVIEW',
    MAPTYPE: 'MAPTYPE'
};
//----------------------------------------------------------------------------------------------------------------------------
//类
var GpsMap = function(mapDivId, mapHeight, mapWidth, CenterLong, CenterLat, CurMapType) {
    //----------------------------------------------------------------------------------------------------------------------------
    if (!GBrowserIsCompatible) {
        return;
    }
    //类参数
    this._map = null; //地图控件  
    this._InfoHtml = null;
    //地图参数配置
    this._mapPars = {
        _mapDivId: mapDivId, //显示地图的div的id     
        _zoom: 15, //缩放比例.默认是15级
        _CenterLong: CenterLong, //中心点经度
        _CenterLat: CenterLat, //中心点纬度
        _maptype: CurMapType, //地图类型        
        _mapSize: new GSize(mapWidth, mapHeight)//地图控件大小

    };
    //控件列表
    this._MapControl = {
        _LargeMapControl: null,
        _ScaleControl: null,
        _OverviewMapControl: null,
        _MapTypeControl: null

    };

    this._Marks = new Array();

    //punlic function
    //----------------------------------------------------------------------------------------------------------------------------    
    //初始化地图
    this.initMap = function() {
        if (this._mapPars._maptype == MapType.GOOGLE) {
            this.initGoogleMap();
        }
        else if (this._mapPars._maptype == MapType.BAIDU) {
            this.initBaiduMap();
        }
        else if (this._mapPars._maptype == MapType.SOUGOU) {
            this.initSougouMap();
        }
    }

    //添加地图控件
    this.AddControl = function(CurControlType) {

        if (this._mapPars._maptype == MapType.GOOGLE) {
            this.AddGoogleControl(CurControlType);
        }
        else if (this._mapPars._maptype == MapType.BAIDU) {
            this.AddBaiduControl(CurControlType);
        }
        else if (this._mapPars._maptype == MapType.SOUGOU) {
            this.AddSouGouControl(CurControlType);
        }
    }

    //添加监控点
    this.AddMonitMark = function(point) {
        var myIcon_google = new GIcon(G_DEFAULT_ICON);

        var marker = new GMarker(point, { icon: myIcon_google, draggable: false, title: "" });

        this._map.clearOverlays();
        this._map.addOverlay(marker);


    }


    //private function
    //----------------------------------------------------------------------------------------------------------------------------
    this.CreateSize = function(w, h) {
        if (this._mapPars._maptype == MapType.GOOGLE) {
            return new GSize(w, h);
        }
        else if (this._mapPars._maptype == MapType.BAIDU) {

        }
        else if (this._mapPars._maptype == MapType.SOUGOU) {

        }
    }

    this.GoToMark = function(index) {
        var point = this._Marks[index - 1];
        if (point != null) {
            this._map.openInfoWindowHtml(point, this._InfoHtml); //弹出信息框
            this._map.panTo(point);
        }
    }


    this.CreatMark = function(lat, lng) {
        var myPoint = new GLatLng(lat, lng);
        this._Marks.push(myPoint);
    }

    this.ShowMarks = function() {
        this._map.clearOverlays();
        for (var i = 0; i < this._Marks.length; i++) {

            var myIcon_google = new GIcon(G_DEFAULT_ICON);
            myIcon_google.iconSize = new GSize(21, 31);
            myIcon_google.image = 'img/' + (i + 1) + '.gif';

            var marker = new GMarker(this._Marks[i], { icon: myIcon_google, draggable: false, title: "" });
            this._map.addOverlay(marker);

        }

    }



    //----------------------------------------------------------------------------------------------------------------------------
    //删除地图控件
    this.RemoveControl = function(CurControlType) {

        if (this._mapPars._maptype == MapType.GOOGLE) {
            this.AddGoogleControl(CurControlType);
        }
        else if (this._mapPars._maptype == MapType.BAIDU) {
            this.AddBaiduControl(CurControlType);
        }
        else if (this._mapPars._maptype == MapType.SOUGOU) {
            this.AddSouGouControl(CurControlType);
        }
    }
    //----------------------------------------------------------------------------------------------------------------------------
    //删除谷歌地图控件
    this.RemoveGoogleControl = function(CurControlType) {
        if (CurControlType == ControlType.LARGE) {
            this._map.removeControl(this._MapControl._LargeMapControl);
            delete this._MapControl._LargeMapControl;
            this._MapControl._LargeMapControl = null;
        }
        else if (CurControlType == ControlType.SCALE) {

            this._map.removeControl(this._MapControl._ScaleControl);
            delete this._MapControl._ScaleControl;
            this._MapControl._ScaleControl = null;
        }

        else if (CurControlType == ControlType.OVERVIEW) {
            this._map.removeControl(this._MapControl._OverviewMapControl);
            delete this._MapControl._OverviewMapControl;
            this._MapControl._OverviewMapControl = null;
        }
        else if (CurControlType == ControlType.MAPTYPE) {
            this._map.removeControl(this._MapControl._MapTypeControl);
            delete this._MapControl._MapTypeControl;
            this._MapControl._MapTypeControl = null;
        }
    }

    //删除百度地图控件
    this.RemoveBaiduControl = function(CurControlType) {

    }

    //删除搜狗地图控件
    this.RemoveSouGouControl = function(CurControlType) {

    }

    //----------------------------------------------------------------------------------------------------------------------------    
    //添加谷歌地图控件
    this.AddGoogleControl = function(CurControlType) {
        if (CurControlType == ControlType.LARGE) {
            this._MapControl._LargeMapControl = new GLargeMapControl();
            this._map.addControl(this._MapControl._LargeMapControl);
        }
        else if (CurControlType == ControlType.SCALE) {
            this._MapControl._ScaleControl = new GScaleControl();
            this._map.addControl(this._MapControl._ScaleControl);
        }

        else if (CurControlType == ControlType.OVERVIEW) {
            this._MapControl._OverviewMapControl = new GOverviewMapControl();
            this._map.addControl(this._MapControl._OverviewMapControl);
        }
        else if (CurControlType == ControlType.MAPTYPE) {
            this._MapControl._MapTypeControl = new GMapTypeControl();
            this._map.addControl(this._MapControl._MapTypeControl);
        }
    }

    //添加百度地图控件
    this.AddBaiduControl = function(CurControlType) {

    }

    //添加搜狗地图控件
    this.AddSouGouControl = function(CurControlType) {

    }
    //----------------------------------------------------------------------------------------------------------------------------
    //谷歌地图的调用方法
    this.initGoogleMap = function() {
        //地图加载成功
        if (GBrowserIsCompatible()) {

            this._map = new GMap2(document.getElementById(mapDivId), { size: this._mapPars._mapSize });
            this._map.enableScrollWheelZoom();
            if (this._map != null) {
                this._map.setCenter(new GLatLng(38.01846, 114.50099), this._mapPars._zoom);
            }
        }

        GEvent.addListener(this._map, "click", function(overlay, point) {
            if (point) {
                var vlat = document.getElementById("lat");
                var vlon = document.getElementById("lon");
                if (vlat != null && vlon != null) {
                    vlat.value = point.y;
                    vlon.value = point.x;

                    _mymap.AddMonitMark(point);
                }

            }
        });
    }


    //百度地图的调用方法

    this.initBaiduMap = function() {
    }


    //搜狗地图的调用方法

    this.initSougouMap = function() {
    }
    //----------------------------------------------------------------------------------------------------------------------------


}



